<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图书管理系统</title>

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <link rel="stylesheet" href="../css/login.css">
    <!--ico 图标-->
    <link rel="shortcut icon" href="../images/favicon.ico" />
    <link rel="stylesheet" href="../css/reset.css" >
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <!-- 引入element-ui样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入element-ui组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <!-- 引入验证码文件 -->
    <script src="../js/jquery-3.6.0.min.js"></script>
    <script src="../js/login.js"></script>
    <script src="../js/yzm.js"></script>
    <!-- axios在线地址 -->
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

</head>

<body>
<div id="app" >
        <header></header>
        <main>
            <div class="inner clearfloat">
                <div class="inner-left">
                    <img src="../images/2.jpg">
                </div>
                <div class="inner-right">
                    <h1>图书管理系统</h1>
                    <el-form ref="form" :model="form" label-width="80px">
                        <el-form-item label="用户名" prop="name">
                            <el-input v-model="form.name" placeholder="用户名"></el-input>
                        </el-form-item>

                        <el-form-item label="密码" prop="pwd">
                            <el-input v-model="form.pwd" placeholder="密码"></el-input>
                        </el-form-item>



                        <!-- 生成验证码 -->
                        <el-form-item label="验证码" prop="yzm">
                            <div class="col-sm-4">
                                <input v-model="form.yzm" type="text" class="form-control" id="yzm" placeholder="验证码">
                            </div>
                            <div class="col-sm-6">
                                <canvas id="canvas" width="100" height="30"></canvas>
                            </div>
                        </el-form-item>


                        <el-form-item>
                            <el-button id="btn" type="primary" @click="onSubmit">登录</el-button>
                            <el-button @click="resetForm('form')">重置</el-button>
                        </el-form-item>
                    </el-form>


                </div>
            </div>
        </main>
        <footer>
            <p>@copyright 2022-2022 吴总科技有限公司</p>
        </footer>
</div>


<script>

    new Vue({
        el: '#app',
        data: {
            form: {
                name: '',
                pwd: '',
                yzm: '',
            },
        },
        methods: {
            onSubmit(event) {
                event.preventDefault();
                if (this.form.name != null && this.form.pwd != null && this.form.yzm != null) {
                    axios.post("/user/login",this.form).then( res => {
                        if (res.data.flag == true ) {
                            localStorage.setItem("user",JSON.stringify(res.data.data.name))
                            console.log(localStorage.getItem("user"))
                            location.href = 'index.html'
                        }else {
                            this.$message.error("用户名或者密码输入错误")
                            this.form.yzm = '';
                            this.form.name = '';
                            this.form.pwd = '';
                        }
                    })
                } else {
                    this.$message.info("请输入用户名，验证码和密码")
                }

            },
            resetForm(form) {
                this.$refs[form].resetFields()
            },

        }
    })
</script>
</body>

</html>